package com.ym.dao.impl;

import com.ym.dao.AccountDao;
import com.ym.pojo.Account;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import java.util.List;

/**
 * @version 1.0
 * 公众号：Java架构栈
 * @Author: 卓不凡
 */

public class AccountDaoImpl implements AccountDao {

    private JdbcTemplate jdbcTemplate;

    public void setJdbcTemplate(JdbcTemplate jdbcTemplate) {
        this.jdbcTemplate = jdbcTemplate;
    }

    //根据用户名查找账户
    @Override
    public Account findAccountByName(String name) {

        List<Account> query = jdbcTemplate.query("select * from account where name  =?", new BeanPropertyRowMapper<>(Account.class), name);

        if(query!=null&&query.size()==1){
            return query.get(0);
        }
        return null;

    }

    //修改账户
    @Override
    public void updateAccount(Account account) {

        jdbcTemplate.update("update account set money= ? where id=?",account.getMoney(),account.getId());

    }
}

